/**
 * Copyright &copy; 2015-2020 <a href="www.dsesa.cn/">ESA</a> All rights reserved.
 */
package com.jeeplus.modules.sys.web;

import com.google.common.collect.Maps;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BadPdfFormatException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.jeeplus.common.Excel2PdfUtil;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.CacheUtils;
import com.jeeplus.common.utils.CookieUtils;
import com.jeeplus.common.utils.MobileUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcelNew;
import com.jeeplus.common.utils.license.MyRSAEnCoderTools;
import com.jeeplus.common.websocket.service.system.SystemInfoSocketHandler;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.security.shiro.session.SessionDAO;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.buzz.menupp.entity.Menuapp;
import com.jeeplus.modules.buzz.menupp.service.MenuappService;
import com.jeeplus.modules.buzz.sysno.mapper.SysNoMapper;
import com.jeeplus.modules.oa.entity.OaNotify;
import com.jeeplus.modules.sys.entity.*;
import com.jeeplus.modules.sys.mapper.SysHomeTongJiMapper;
import com.jeeplus.modules.sys.security.FormAuthenticationFilter;
import com.jeeplus.modules.sys.security.SystemAuthorizingRealm.Principal;
import com.jeeplus.modules.sys.service.SysHomeTongJiService;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.wxMsg.SendWX;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.web.util.SavedRequest;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;

/**
 * 登录Controller
 * @author jeeplus
 * @version 2016-5-31
 */
@Api(value = "LoginController", description = "登录控制器")
@Controller
public class LoginController extends BaseController{

	public static final String OAUTH_CODE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";

	@Autowired
	private SessionDAO sessionDAO;

	@Autowired
	private MenuappService menuappService;

	@Autowired
	private SysHomeTongJiService sysHomeTongJiService;

	@Autowired
	private SysHomeTongJiMapper sysHomeTongJiMapper;


	@Autowired
	private SystemService systemService;

	@Autowired
	SysNoMapper sysNoMapper;

	@Autowired
	ActTaskService actTaskService;

	/**
	 * 管理登录
	 * @throws IOException
	 */
	@ApiOperation(notes = "login", httpMethod = "POST", value = "用户登录")
	@ApiImplicitParams({@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "query",dataType = "string"),
			@ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query",dataType = "string"),
			@ApiImplicitParam(name="mobileLogin",value = "接口标志",required = true, paramType = "query",dataType = "string")})
	@RequestMapping(value = "${adminPath}/login")
	public String login(HttpServletRequest request, HttpServletResponse response) throws IOException {

		Principal principal = UserUtils.getPrincipal();

		if (logger.isDebugEnabled()){
			logger.debug("login, active session size: {}", sessionDAO.getActiveSessions(false).size());
		}

		// 如果已登录，再次访问主页，则退出原账号。
		if (Global.TRUE.equals(Global.getConfig("notAllowRefreshIndex"))){
			CookieUtils.setCookie(response, "LOGINED", "false");
		}

		// 如果已经登录，则跳转到管理首页
		if(principal != null && !principal.isMobileLogin()){
			return "redirect:" + adminPath;
		}
		 SavedRequest savedRequest = WebUtils.getSavedRequest(request);//获取跳转到login之前的URL
		// 如果是手机没有登录跳转到到login，则返回JSON字符串
		 if(savedRequest != null){
			 String userAgent = request.getHeader( "user-agent" ).toLowerCase();
			 if (userAgent.indexOf( "micromessenger" )>- 1 && "1".equals(Global.getConfig("wxsend"))){ //微信客户端
				//加入企业微信无感登录
				 Integer serverPort = request.getServerPort();
				 String port = (null != serverPort && serverPort == 80) ? "" : ":" + serverPort.toString();
				 String url = "http://" + Global.getConfig("domain.url"); // 服务器地址
				 url = url + request.getContextPath() + adminPath + "/wx/outh";
				 try{
					 url = URLEncoder.encode(url, "utf-8");
				 }catch (UnsupportedEncodingException e){
					 e.printStackTrace();
				 }
				 System.out.println(url);
				 String weixinUrl = String.format(OAUTH_CODE_URL, Global.getConfig("corpid"), url, "state");
				 return "redirect:" + weixinUrl;
			}
		 }


		return "modules/sys/login/sysLogin";
	}

	/**
	 * 登录失败，真正登录的POST请求由Filter完成
	 */
	@RequestMapping(value = "${adminPath}/login", method = RequestMethod.POST)
	public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) {
		Principal principal = UserUtils.getPrincipal();

		// 如果已经登录，则跳转到管理首页
		if(principal != null){
			return "redirect:" + adminPath;
		}

		String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
		boolean rememberMe = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM);
		boolean mobile = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_MOBILE_PARAM);
		String exception = (String)request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		String message = (String)request.getAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM);

		if (StringUtils.isBlank(message) || StringUtils.equals(message, "null")){
			message = "用户或密码错误, 请重试.";
		}

		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, username);
		model.addAttribute(FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM, rememberMe);
		model.addAttribute(FormAuthenticationFilter.DEFAULT_MOBILE_PARAM, mobile);
		model.addAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME, exception);
		model.addAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM, message);

		if (logger.isDebugEnabled()){
			logger.debug("login fail, active session size: {}, message: {}, exception: {}",
					sessionDAO.getActiveSessions(false).size(), message, exception);
		}

		// 非授权异常，登录失败，验证码加1。
		// if (!UnauthorizedException.class.getName().equals(exception)){
		// 	model.addAttribute("isValidateCodeLogin", isValidateCodeLogin(username, true, false));
		// }

		// 验证失败清空验证码
		// request.getSession().setAttribute(ValidateCodeServlet.VALIDATE_CODE, IdGen.uuid());

		// 如果是手机登录，则返回JSON字符串
		if (mobile){
			AjaxJson j = new AjaxJson();
			j.setSuccess(false);
			j.setMsg(message);
			j.put("username", username);
			j.put("name","");
			j.put("mobileLogin", mobile);
			j.put("JSESSIONID", "");
	        return renderString(response, j.getJsonStr());
		}

		return "modules/sys/login/sysLogin";
	}

	/**
	 * 管理登录
	 * @throws IOException
	 */
	@RequestMapping(value = "${adminPath}/logout", method = RequestMethod.GET)
	public String logout(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
		Principal principal = UserUtils.getPrincipal();
		// 如果已经登录，则跳转到管理首页
		if(principal != null){
			UserUtils.getSubject().logout();

		}
	   // 如果是手机客户端退出跳转到login，则返回JSON字符串
			String ajax = request.getParameter("__ajax");
			if(	ajax!=null){
				model.addAttribute("success", "1");
				model.addAttribute("msg", "退出成功");
				return renderString(response, model);
			}
		 return "redirect:" + adminPath+"/login";
	}

	/**
	 * 登录成功，进入管理首页
	 */
	@RequestMapping(value = "${adminPath}")
	public String index(HttpServletRequest request, HttpServletResponse response) {
		Principal principal = UserUtils.getPrincipal();
		// 登录成功后，验证码计算器清零
		isValidateCodeLogin(principal.getLoginName(), false, true);

		if (logger.isDebugEnabled()){
			logger.debug("show index, active session size: {}", sessionDAO.getActiveSessions(false).size());
		}

		// 如果已登录，再次访问主页，则退出原账号。
		if (Global.TRUE.equals(Global.getConfig("notAllowRefreshIndex"))){
			String logined = CookieUtils.getCookie(request, "LOGINED");
			if (StringUtils.isBlank(logined) || "false".equals(logined)){
				CookieUtils.setCookie(response, "LOGINED", "true");
			}else if (StringUtils.equals(logined, "true")){
				UserUtils.getSubject().logout();
				return "redirect:" + adminPath + "/login";
			}
		}

		// 如果是手机登录，则返回JSON字符串
		if (principal.isMobileLogin()){
			if (request.getParameter("login") != null){
				return renderString(response, principal);
			}
			if (request.getParameter("index") != null){
				return "modules/sys/login/sysIndex";
			}
			return "redirect:" + adminPath + "/login";
		}

		OaNotify oaNotify = new OaNotify();
		oaNotify.setSelf(true);
		oaNotify.setReadFlag("0");
//		Page<OaNotify> page = oaNotifyService.find(new Page<OaNotify>(request, response), oaNotify);
//		request.setAttribute("page", page);
//		request.setAttribute("count", page.getList().size());//未读通知条数
		Map result = actTaskService.dbCount("");
//		Page<OaNotify> page = oaNotifyService.find(new Page<OaNotify>(request, response), oaNotify);
//		request.setAttribute("page", page);
		request.setAttribute("count", result.get("count"));//待办总条数
		request.setAttribute("dbCount", result.get("dbCount"));//待办条数
		request.setAttribute("csCount", result.get("csCount"));//未审阅抄送
//		MailBox mailBox = new MailBox();
//		mailBox.setReceiver(UserUtils.getUser());
//		mailBox.setReadstatus("0");//筛选未读
//		request.setAttribute("noReadCount", mailBoxService.getCount(mailBox));
//		Page<MailBox> mailPage = mailBoxService.findPage(new MailPage<MailBox>(request, response), mailBox);
//		request.setAttribute("mailPage", mailPage);

		if(UserUtils.getMenuList().size() == 0){
			return "modules/sys/login/noAuth";
		}else{
			// 默认风格
			String indexStyle ;
			if(MobileUtils.checkAgentIsMobile(request.getHeader("User-Agent"))){//如果是移动，默认使用左侧菜单，显示效果较好
				indexStyle = "ani";
			}else{//如果是pc端，默认使用jeeplus.properties中的配置项，jp横向菜单，ani左侧菜单
				indexStyle = Global.getDefaultTheme();
			}


			Cookie[] cookies = request.getCookies();
			for (Cookie cookie : cookies) {
				if (cookie == null || StringUtils.isEmpty(cookie.getName())) {
					continue;
				}
				if (cookie.getName().equalsIgnoreCase("style")) {
					indexStyle = cookie.getValue();
				}
			}
			// 要添加自己的风格，复制下面三行即可
			if (StringUtils.isNotEmpty(indexStyle)
					&& indexStyle.equalsIgnoreCase("jp")) {
				return "modules/sys/login/sysIndex-jp";
			}

			return "modules/sys/login/sysIndex";
		}



	}
	/**
	 * 切换风格
	 */
	@ResponseBody
	@RequestMapping(value = "${adminPath}/style/{style}")
	public String getStyleInCookie(@PathVariable String style, HttpServletRequest request, HttpServletResponse response){
		if (StringUtils.isNotBlank(style)){
			CookieUtils.setCookie(response, "style", style);
		}else{
			style = CookieUtils.getCookie(request, "style");
		}
		return style;
	}


	/**
	 * 获取主题颜色方案
	 */
	@ResponseBody
	@RequestMapping(value = "${adminPath}/theme/{theme}")
	public String getThemeInCookie(@PathVariable String theme, HttpServletRequest request, HttpServletResponse response){
		if (StringUtils.isNotBlank(theme)){
			if(theme.contains("_")){
				String style = theme.split("_")[0];
				theme = theme.split("_")[1];
				if(style.equals("white")){
					CookieUtils.setCookie(response, "white", "theme-whbl");
				}else{
					CookieUtils.setCookie(response, "white", "");
				}
				CookieUtils.setCookie(response, "theme", theme);
			}else{
				CookieUtils.setCookie(response, "theme", theme);
			}
		}else{
			theme = CookieUtils.getCookie(request, "theme");
		}
		return theme;
	}

	/**
	 * 是否启用tab
	 */
	@RequestMapping(value = "${adminPath}/tab/{tab}")
	public String getTabInCookie(@PathVariable String tab, HttpServletRequest request, HttpServletResponse response){
		if (StringUtils.isNotBlank(tab)){
			CookieUtils.setCookie(response, "tab", tab);
		}else{
			tab = CookieUtils.getCookie(request, "tab");
		}
		return "redirect:"+request.getParameter("url");
	}

	/**
	 * 是否是验证码登录
	 * @param useruame 用户名
	 * @param isFail 计数加1
	 * @param clean 计数清零
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static boolean isValidateCodeLogin(String useruame, boolean isFail, boolean clean){
		Map<String, Integer> loginFailMap = (Map<String, Integer>)CacheUtils.get("loginFailMap");
		if (loginFailMap==null){
			loginFailMap = Maps.newHashMap();
			CacheUtils.put("loginFailMap", loginFailMap);
		}
		Integer loginFailNum = loginFailMap.get(useruame);
		if (loginFailNum==null){
			loginFailNum = 0;
		}
		if (isFail){
			loginFailNum++;
			loginFailMap.put(useruame, loginFailNum);
		}
		if (clean){
			loginFailMap.remove(useruame);
		}
		return loginFailNum >= 3;
	}


	/**
	 * 首页
	 * @throws IOException
	 */
	@RequestMapping(value = "${adminPath}/home")
	public String home(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
		User user= UserUtils.getUser();
		model.addAttribute("user",user);
		return "modules/sys/login/sysHome";

	}

	/**
	 * 首页
	 * @throws IOException
	 */
	@RequestMapping(value = "${adminPath}/homeApp")
	public String homeApp(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
		User user= UserUtils.getUser();
		model.addAttribute("user",user);
		Map result = actTaskService.dbCount("");
		request.setAttribute("dbCount", result.get("dbCount"));//待办条数
		request.setAttribute("csCount", result.get("csCount"));//未审阅抄送
		return "modules/sys/login/sysHomeApp";

	}

	/**
	 * 获取机器码
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "${adminPath}/getMechine")
	public AjaxJson getMechine(){
		AjaxJson j = new AjaxJson();
		String code = MyRSAEnCoderTools.getMechineCode();
		if(!"".equals(code)){
			j.setSuccess(true);
			j.setMsg(code);
		}else {
			j.setSuccess(false);
			j.setMsg("获取机器码失败");
		}
		return j;
	}

	/**
	 * 车辆品牌统计
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "${adminPath}/brandTongTi")
	public AjaxJson brandTongTi(){
		AjaxJson j = new AjaxJson();
		String code = MyRSAEnCoderTools.getMechineCode();
		if(!"".equals(code)){
			j.setSuccess(true);
			j.setMsg(code);
		}else {
			j.setSuccess(false);
			j.setMsg("获取机器码失败");
		}
		return j;
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getPdf")
	public void getPdf(String pdfName, HttpServletResponse response) {
		if(null != pdfName && !"".equals(pdfName)){
			try {
				PdfReader pdfReader = new PdfReader(Excel2PdfUtil.hc + pdfName);
				Document document = new Document(pdfReader.getPageSize(1));
				int n = pdfReader.getNumberOfPages();
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				PdfCopy copy = new PdfCopy(document, baos);
				document.open();
				for(int i = 1; i <= n; i++) {
					PdfImportedPage page = copy.getImportedPage(pdfReader, i);
					copy.addPage(page);
				}
				document.close();

				response.setContentType("application/pdf");
				response.setContentLength(baos.size());
				response.setHeader("Expires", "0");
				response.setHeader("Cache-Control",
						"must-ridate, post-check=0, pre-check=0");
				response.setHeader("Pragma", "public");
				ServletOutputStream out = response.getOutputStream();
				//将字节流baos中的内容写入响应流
				baos.writeTo(out);
				copy.close();
				pdfReader.close();
				out.flush();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (BadPdfFormatException e) {
				e.printStackTrace();
			} catch (DocumentException e) {
				e.printStackTrace();
			}
		}
	}

	@RequestMapping(value = "${adminPath}/preView")
	public String preView(String pdfName,Model model) {
		model.addAttribute("pdfName", pdfName);
		return "modules/common/preView";
	}

	@RequestMapping(value = "${adminPath}/viewXsDetail")
	public String viewXsDetail(String xsId,Model model) {
		model.addAttribute("xsId", xsId);
		return "modules/sys/login/xsDetail";
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getSellUnitPerData")
	public AjaxJson getSellUnitPerData() {
		AjaxJson j = new AjaxJson();
		try {
			LinkedHashMap map = sysHomeTongJiService.getSellUnitPerData();
			j.setSuccess(true);
			j.setBody(map);
		}catch (Exception e){
			System.out.println(e.getMessage());
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getSellData")
	public AjaxJson getSellData() {
		AjaxJson j = new AjaxJson();
		try {
			LinkedHashMap map = sysHomeTongJiService.getSellData();
			j.setSuccess(true);
			j.setBody(map);
		}catch (Exception e){
			System.out.println(e.getMessage());
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getRiskSellData")
	public AjaxJson getRiskSellData() {
		AjaxJson j = new AjaxJson();
		try {
			LinkedHashMap map = sysHomeTongJiService.getRiskSellData();
			j.setSuccess(true);
			j.setBody(map);
		}catch (Exception e){
			System.out.println(e.getMessage());
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getRiskArrearsData")
	public AjaxJson getRiskArrearsData() {
		AjaxJson j = new AjaxJson();
		try {
			LinkedHashMap map = sysHomeTongJiService.getRiskArrearsData();
			j.setSuccess(true);
			j.setBody(map);
		}catch (Exception e){
			System.out.println(e.getMessage());
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/")
	public List<Map> getSelectList(String beanName, String tableName, String colName, String conExtral, String conditions){
		if(!"".equals(conditions)){
			conExtral = conExtral + "," + conditions;
		}

		String []condition = conExtral.split(",");
		return systemService.getSelectList1(beanName,tableName,colName,condition);
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/findTongTjByCompId")
	public AjaxJson findTongTjByCompId(String company) {
		AjaxJson j = new AjaxJson();
		try {
			LinkedHashMap linkedHashMap = new LinkedHashMap();
			company	= UserUtils.getUser().getId();

			Map map = sysHomeTongJiService.findTongTjByCompId(company);
			linkedHashMap.put("result",map);
			j.setSuccess(true);
			j.setBody(linkedHashMap);
		}catch (Exception e){
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getHomePie")
	public AjaxJson getHomePie(String user) {
		AjaxJson j = new AjaxJson();
		try {
			user = UserUtils.getUser().getId();
			LinkedHashMap map = sysHomeTongJiService.getHomePie(user);
			j.setSuccess(true);
			j.setBody(map);
		}catch (Exception e){
			System.out.println(e.getMessage());
			j.setSuccess(false);
		}finally {
			return j;
		}
	}

	@RequestMapping(value = "${adminPath}/cgDataView")
	public String cgDataView(String type,String company,Model model) {
		model.addAttribute("type", type);
		model.addAttribute("company", company);
		return "modules/sys/login/cgDataView";
	}

/*	@ResponseBody
	@RequestMapping(value = "${adminPath}/qktjDataDetail")
	public Map<String, Object> qktjDataDetail(String type,String company, HttpServletRequest request, HttpServletResponse response, Model model) {
		Arch2QKBReport arch2QKBReport = new Arch2QKBReport();
		arch2QKBReport.setCompany(new Office(company));
		arch2QKBReport.setDkyh(type);
		Page<Arch2QKBReport> page = arch2QKBReportService.findPage1(new Page<Arch2QKBReport>(request, response),arch2QKBReport);
		return getBootstrapData(page);
	}*/

	@ResponseBody
	@RequestMapping(value = "${adminPath}/changUserCom")
	public String changUserCom(String companyId,String companyName,Model model){
		User user = UserUtils.getUser();
		if(StringUtils.isNotBlank(companyId) && StringUtils.isNotBlank(companyName)){
			Office company = new Office(companyId);
			company.setName(companyName);
			user.setCompany(company);
			CacheUtils.put(UserUtils.USER_CACHE, UserUtils.USER_CACHE_ID_ + user.getId(),user);
		}
		model.addAttribute("user",user);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/getActid")
	public String getActid(String key){
		return sysNoMapper.getActid(key);
	}

	@ResponseBody
	@RequestMapping(value = "${adminPath}/sendWxMsg")
	public boolean sendWxMsg(String userName,String msg){
		try {
			SendWX.send(userName,msg,new TaskEntity());
			return true;
		}catch (Exception e){
			return false;
		}
	}

	@RequestMapping(value = "${adminPath}/wxTest")
	public String wxTest() {
		return "modules/sys/login/wxTest";
	}

	/**
	 * 获取九宫格报表list
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "${adminPath}/getbbList")
	public Map getbbList(){
		List<Menuapp> menuappList = menuappService.findList(new Menuapp());
		List<DictValue> dictValueList = DictUtils.getDictList("Sys_menuapp");
		Map map = new HashMap();
		for(DictValue dictValue : dictValueList){
			String key = dictValue.getLabel();
			List valueList = new ArrayList();
			for(Menuapp menuapp :menuappList){
				if(menuapp.getClasstype().equals(dictValue.getValue())){
					valueList.add(menuapp);
				}
			}
			if(valueList != null && valueList.size() > 0){
				map.put(key,valueList);
			}

		}
		return map;
	}



}
